package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.system.domain.vo.SysFormPlanListVo;
import jakarta.servlet.http.HttpServletResponse;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysFormPlan;
import com.ruoyi.system.service.ISysFormPlanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 单计划Controller
 *
 * @author ruoyi
 * @date 2025-08-31
 */
@RestController
@RequestMapping("/system/form_plan")
public class SysFormPlanController extends BaseController
{
    @Autowired
    private ISysFormPlanService sysFormPlanService;

    /**
     * 查询单计划列表
     */
    @PreAuthorize("@ss.hasPermi('system:form_plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysFormPlan sysFormPlan)
    {
        startPage();
        List<SysFormPlan> list = sysFormPlanService.selectSysFormPlanList(sysFormPlan);
        return getDataTable(list);
    }

    /**
     * 导出单计划列表
     */
    @PreAuthorize("@ss.hasPermi('system:form_plan:export')")
    @Log(title = "单计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysFormPlan sysFormPlan)
    {
        List<SysFormPlan> list = sysFormPlanService.selectSysFormPlanList(sysFormPlan);
        ExcelUtil<SysFormPlan> util = new ExcelUtil<SysFormPlan>(SysFormPlan.class);
        util.exportExcel(response, list, "单计划数据");
    }

    /**
     * 获取单计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:form_plan:query')")
    @GetMapping(value = "/{planId}")
    public AjaxResult getInfo(@PathVariable("planId") Long planId)
    {
        return success(sysFormPlanService.selectSysFormPlanByPlanId(planId));
    }

    /**
     * 新增单计划
     */
    @PreAuthorize("@ss.hasPermi('system:form_plan:add')")
    @Log(title = "单计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysFormPlan sysFormPlan)
    {
        return sysFormPlanService.insertSysFormPlan(sysFormPlan);
    }

    /**
     * 修改单计划
     */
    @PreAuthorize("@ss.hasPermi('system:form_plan:edit')")
    @Log(title = "单计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysFormPlan sysFormPlan)
    {
        return toAjax(sysFormPlanService.updateSysFormPlan(sysFormPlan));
    }

    /**
     * 删除单计划
     */
    @PreAuthorize("@ss.hasPermi('system:form_plan:remove')")
    @Log(title = "单计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{planIds}")
    public AjaxResult remove(@PathVariable Long[] planIds)
    {
        return toAjax(sysFormPlanService.deleteSysFormPlanByPlanIds(planIds));
    }


    @PreAuthorize("@ss.hasPermi('system:form_plan:form_plan_list')")
    @GetMapping("/form_plan_list")
    public TableDataInfo formPlanList(@RequestParam(value = "projectId",required = false)Long projectId)
    {
        startPage();
        List<SysFormPlanListVo> list = sysFormPlanService.selectFormPlanList(projectId);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('system:form_plan:appList')")
    @GetMapping("/app_form_plan_list")
    public AjaxResult appFormPlanList()
    {
        List<SysFormPlanListVo> list = sysFormPlanService.selectFormPlanList(null);
        return AjaxResult.success(list);
    }


}
